package com.example.protobuf.controller;

import com.example.protobuf.response.Judgement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;

@RestController
@RequestMapping(value = "/api")
public class QuestionnaireSaveController {

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/{user}")
    public Judgement.Judge getUser(HttpServletRequest servletRequest) throws IOException {
        HttpHeaders headers = new HttpHeaders();
        Judgement.Judge judge = restTemplate.exchange(
                "http://localhost:8081/api/json", HttpMethod.GET,
                new HttpEntity<>(null, headers), Judgement.Judge.class).getBody();
        return judge;
    }

}
